package com.mollytask;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;

import com.mollytask.bean.MyUser;
import com.mollytask.login.WelcomeActivity;

import cn.bmob.v3.BmobUser;

public class SplashActivity extends AppCompatActivity {


    private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {

            //获取当前用户，若为空则跳转登录注册界面，否则直接进入主界面
            MyUser myUser = BmobUser.getCurrentUser(MyUser.class);
            if (myUser == null) {
                Intent intent = new Intent(SplashActivity.this, WelcomeActivity.class);
                startActivity(intent);
                finish();
            } else {
                Intent intent = new Intent(SplashActivity.this, MainActivity.class);
                startActivity(intent);
                finish();
            }

        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);

        //启动页显示两秒之后跳转
        mHandler.sendEmptyMessageDelayed(1000, 2000);


    }

}
